<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  users
 */

class m_users_services_UserService
{	
	/**
	 * @var m_users_services_UserService
	 */
	private static $instance;
	
	/**
	 * Constructor
	 */
	private function __construct()
	{
		// Code if needed...
	}
	
	/**
	 * @return m_users_services_UserService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = new self();
		}
		return self::$instance;
	}
	
	public function initFirstUser($values)
	{
		$documentProvider = f_document_Provider::getInstance();
		
		$groupsCount = $documentProvider->loadDocuments("modules_users/group")->count();
		
		if($groupsCount == 0)
		{
			$group = m_users_documents_Group::createNew();
			
			$group->setLevel(100)->setAuthor("pagizer")->setLabel("Super Admin")->save();
		}
	}
	
	/**
	 * Check if there is at least one user in db
	 * @return boolean
	 */
	public function hasAdminUser()
	{
		$documentProvider = f_document_Provider::getInstance();
		
		return $documentProvider->loadDocuments("modules_users/user")->count('*') > 0;
	}
}